﻿@model Sys_MenuEidtModel
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN VALIDATION STATES-->
        <div class="portlet box green">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-reorder"></i>@ViewBag.TableTitle
                </div>
                <div class="tools">
                </div>
            </div>
            <div class="portlet-body form">
                <!-- BEGIN FORM-->
                @using (Html.BeginForm("Edit", null, null, FormMethod.Post, new
                {
                    @class = "form-horizontal",
                    @novalidate = "novalidate",
                    @enctype = "multipart/form-data"
                }))
                {
                    <div class="form-body">
                        @Html.AntiForgeryToken()
                        @Html.Partial("_Tip")
                        @Html.HiddenFor(s => s.Id)


                        <div class="form-group">
                            <label class="control-label col-md-3">
                                父级菜单
                                <span class="required">
                                    *
                                </span>
                            </label>
                            <div class="col-md-4">
                                @Html.Action("MenuSelect")
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3">
                                @Html.LabelFor(s => s.Name)
                                <span class="required">
                                    *
                                </span>
                            </label>
                            <div class="col-md-4">
                                @Html.TextBoxFor(s => s.Name, new { @class = "form-control" })
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3">
                                @Html.LabelFor(s => s.Link)
                            </label>
                            <div class="col-md-4">
                                @Html.TextBoxFor(s => s.Link, new { @class = "form-control" })
                            </div>
                        </div>
                    </div>
                    <div class="form-actions fluid">
                        <div class="col-md-offset-3 col-md-9">
                            <button type="submit" class="btn green">Submit</button>
                            <button type="button" class="btn default" onclick="location.href='@Url.Action("List")'">Cancel</button>
                        </div>
                    </div>
                }
                <!-- END FORM-->
            </div>
            <!-- END VALIDATION STATES-->
        </div>
    </div>
</div>

@section script{
    <script src="~/assets/zrjs/menu/edit.js"></script>
    <script>
        $(function () {
            FormValidation.init();
            FormComponents.init();
            var parentId = '@(Model?.ParentId)';

            setTimeout(function () {
                if (!!parentId) {
                    var option = $('#menuSelect').val(parentId);
                    if (!!option) {
                        $(option).trigger('change');
                    }
                }
            }, 150);

            $('#menuSelect')
                .select2({
                    templateResult: function (data) {
                        if (!data.element) {
                            return data.text;
                        }
                        var $element = $(data.element);
                        var $wrapper = $('<span></span>');
                        $wrapper.attr('style', $($element[0]).attr('style'));
                        $wrapper.text(data.text);
                        return $wrapper;
                    }
                });
        })
    </script>
}